define([], function() {

	var ModalDialog = function(arg) {
		/*
				opacity:0.5,
			    txt:'hahaha',
			    time:1000
				 * */
		this.arg = arg;
		this._init();
	}

	ModalDialog.prototype = {

		_init: function() {
			this._getStyle();
			this._show();
			var that = this;
			setTimeout(function() {
				that._destory();
			}, this.arg.time);
            
		},

		_show: function() {
			this.modalContainner = document.createElement('div');
			this.modalContainner.setAttribute('class', 'modalContainner');
			var _innerHtml = '';
			_innerHtml += '<div class="modalDialog"><p class="modalTxt">' + this.arg.txt + '</p></div>';
			this.modalContainner.innerHTML = _innerHtml;
			document.body.appendChild(this.modalContainner);
		},

		_getStyle: function() {
			if(document.getElementById('modalStyle') == null) {
				var styleTap = document.createElement('style');
				styleTap.setAttribute('id', 'modalStyle');
				var content = '';
				content += '.modalContainner{position: absolute;width: 100%;height: 100%;background: black;opacity: ' + this.arg.opacity + ';top: 0px;left: 0px;}';
				content += '.modalTxt{width: 40%;height: 30%;background: white;position: absolute;top: 0px;bottom: 0px;left: 0px;right: 0px;margin: auto;}';
				styleTap.innerHTML = content;
				document.head.appendChild(styleTap);
			}
		},

		_destory: function() {
			this.modalContainner.remove();
		}

	}
    
    //一打开页面自动执行
//	var myModal = new ModalDialog({
//		opacity:0.5,
//		txt:"haha",
//		time:1000
//	});
  
    return ModalDialog;

	
	
	
	
	
});